JavaScript arrays problems of DSA